/**
 * @file:          ch32v30x_module_v11.h
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2023.06.09
 * @version:       1.0.0
 * @par copyright (c):
 *
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.06.09,18:31:37
 */
#ifndef _CH32V30X_MODULE_V11_H_
#define _CH32V30X_MODULE_V11_H_

/* Include Files **************************************************************/
#include "Datatype.h"
#include "ch32v30x_module.h"

/* Macro Definition ***********************************************************/
#define UART_NUM_USED 3
#if UART_NUM_USED == 1

#define USART_USED (USART1)
#define TX_DMA_Channel (DMA1_Channel4) //
#define RX_DMA_Channel (DMA1_Channel5) //

#elif UART_NUM_USED == 3

#define USART_USED (USART3)
#define TX_DMA_Channel (DMA1_Channel2) // DMA1_Channel4
#define RX_DMA_Channel (DMA1_Channel3) // DMA1_Channel5

#endif

/* Data Type Define ***********************************************************/
typedef struct ch32v30x_module_v11
{
    /* public data */
    GpioGeneralType *param_pin_PA0;
    GpioGeneralType *param_pin_PA1;
    GpioGeneralType *param_pin_PA2;
    GpioGeneralType *param_pin_PA3;
    GpioGeneralType *param_pin_PA4;
    GpioGeneralType *param_pin_PA5;
    GpioGeneralType *param_pin_PA6;
    GpioGeneralType *param_pin_PA7;
    GpioGeneralType *param_pin_PA8;
    GpioGeneralType *param_pin_PA9;
    GpioGeneralType *param_pin_PA10;
    GpioGeneralType *param_pin_PA11;
    GpioGeneralType *param_pin_PA12;
    GpioGeneralType *param_pin_PA13;
    GpioGeneralType *param_pin_PA14;
    GpioGeneralType *param_pin_PA15;
    GpioGeneralType *param_pin_PB0;
    GpioGeneralType *param_pin_PB1;
    GpioGeneralType *param_pin_PB2;
    GpioGeneralType *param_pin_PB3;
    GpioGeneralType *param_pin_PB4;
    GpioGeneralType *param_pin_PB5;
    GpioGeneralType *param_pin_PB6;
    GpioGeneralType *param_pin_PB7;
    GpioGeneralType *param_pin_PB8;
    GpioGeneralType *param_pin_PB9;
    GpioGeneralType *param_pin_PB10;
    GpioGeneralType *param_pin_PB11;
    GpioGeneralType *param_pin_PB12;
    GpioGeneralType *param_pin_PB13;
    GpioGeneralType *param_pin_PB14;
    GpioGeneralType *param_pin_PB15;
    GpioGeneralType *param_pin_PC0;
    GpioGeneralType *param_pin_PC1;
    GpioGeneralType *param_pin_PC2;
    GpioGeneralType *param_pin_PC3;
    GpioGeneralType *param_pin_PC4;
    GpioGeneralType *param_pin_PC5;
    GpioGeneralType *param_pin_PC6;
    GpioGeneralType *param_pin_PC7;
    GpioGeneralType *param_pin_PC8;
    GpioGeneralType *param_pin_PC9;
    GpioGeneralType *param_pin_PC10;
    GpioGeneralType *param_pin_PC11;
    GpioGeneralType *param_pin_PC12;
    GpioGeneralType *param_pin_PC13;
    GpioGeneralType *param_pin_PC14;
    GpioGeneralType *param_pin_PC15;
    GpioGeneralType *param_pin_PD0;
    GpioGeneralType *param_pin_PD1;
    GpioGeneralType *param_pin_PD2;
    GpioGeneralType *param_pin_PD3;
    GpioGeneralType *param_pin_PD4;
    GpioGeneralType *param_pin_PD5;
    GpioGeneralType *param_pin_PD6;
    GpioGeneralType *param_pin_PD7;
    GpioGeneralType *param_pin_PD8;
    GpioGeneralType *param_pin_PD9;
    GpioGeneralType *param_pin_PD10;
    GpioGeneralType *param_pin_PD11;
    GpioGeneralType *param_pin_PD12;
    GpioGeneralType *param_pin_PD13;
    GpioGeneralType *param_pin_PD14;
    GpioGeneralType *param_pin_PD15;
    GpioGeneralType *param_pin_PE0;
    GpioGeneralType *param_pin_PE1;
    GpioGeneralType *param_pin_PE2;
    GpioGeneralType *param_pin_PE3;
    GpioGeneralType *param_pin_PE4;
    GpioGeneralType *param_pin_PE5;
    GpioGeneralType *param_pin_PE6;
    GpioGeneralType *param_pin_PE7;
    GpioGeneralType *param_pin_PE8;
    GpioGeneralType *param_pin_PE9;
    GpioGeneralType *param_pin_PE10;
    GpioGeneralType *param_pin_PE11;
    GpioGeneralType *param_pin_PE12;
    GpioGeneralType *param_pin_PE13;
    GpioGeneralType *param_pin_PE14;
    GpioGeneralType *param_pin_PE15;

} ch32v30x_module_v11;

/* Variable Declare ***********************************************************/

/* Inline Function Define *****************************************************/

/* Function Declare ***********************************************************/
uint8 ch32v30x_module_v11_Init(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitSystem(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitClock(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitGpio(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitAdc(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitUart(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitDMA(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitPwm(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitTimmer(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitSpi(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitInternalFlash(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitInputPulseCounter(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitExternalInterrupt(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitIWDG(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitWWDG(struct ch32v30x_module *self);
void ch32v30x_module_v11_InitDelay(struct ch32v30x_module *self);
void ch32v30x_module_v11_GpioToggle(uint16 gpio);
void ch32v30x_module_v11_GpioSet(uint16 gpio);
void ch32v30x_module_v11_GpioReset(uint16 gpio);
uint16 ch32v30x_module_v11_GpioRead(uint16 gpio);
void ch32v30x_module_v11_DelayMs(struct ch32v30x_module *self, uint16 x_ms);
void ch32v30x_module_v11_DelayUs(ch32v30x_module *self, uint16 x_us);
int16 ch32v30x_module_v11_AdcGetResult(uint16 adc_num, uint16 channel);
void ch32v30x_module_v11_StartTimmer();
void ch32v30x_module_v11_StopTimmer();
void ch32v30x_module_v11_GpioPinInit(struct ch32v30x_module *self, uint16 gpio, uint16 gpio_mode);
uint16 ch32v30x_module_v11_GpioModeTranslate(uint16 gpio_mode);
void ch32v30x_module_v11_SetPwm(struct ch32v30x_module *self, uint16 pwm_channel, float32 pwm_duty);
void ch32v30x_module_v11_SetAllPwm(struct ch32v30x_module *self, float32 pwm_duty_ch1, float32 pwm_duty_ch2, float32 pwm_duty_ch3, float32 pwm_duty_ch4);
uint8 ch32v30x_module_v11_SPI_WriteReadData(uint16 *write_data, uint8 *read_data, uint16 data_len, uint16 over_time);
uint8 ch32v30x_module_v11_SPI_WriteReg(uint8 addr, uint8 *data, uint16 data_len);
uint8 ch32v30x_module_v11_SPI_ReadReg(uint8 addr, uint8 *data, uint16 data_len);
uint8 ch32v30x_module_v11_SPI_WriteByte(uint8 data);
uint8 ch32v30x_module_v11_SPI_ReadByte();
void ch32v30x_module_v11_EnableInterrupt();
void ch32v30x_module_v11_EnableNvicInterrupt();
void ch32v30x_module_v11_DisableNvicInterrupt();
void ch32v30x_module_v11_ADC_StartConversion();
void ch32v30x_module_v11_ADC_WaitConversionComplete();
void ch32v30x_module_v11_FlashWriteOnePage256Bytes(uint32 flash_start_addr, uint32 addr_n_256, uint32 *data_buff);
void ch32v30x_module_v11_FlashWriteHalfWord(uint32 flash_start_addr, uint32 data_addr_offset, uint16 data);
void ch32v30x_module_v11_FlashEraseOnePage256Bytes_Fast(uint32 flash_start_addr, uint32 addr_n_256);
void ch32v30x_module_v11_FlashEraseOnePage32KBytes_Fast(uint32 flash_start_addr, uint32 addr_n_32k);
void ch32v30x_module_v11_FlashEraseOnePage32KBytes(uint32 flash_start_addr, uint32 flash_end_addr);
void ch32v30x_module_v11_FlashUnlockFast();
void ch32v30x_module_v11_FlashLockFast();
void ch32v30x_module_v11_FlashUnlock();
void ch32v30x_module_v11_FlashLock();
void ch32v30x_module_v11_FlashClearFlag();
uint16_t ch32v30x_module_v11_GetInputPulseCounter();
void ch32v30x_module_v11_ClearInputPulseCounter();
void ch32v30x_module_v11_SetInputPulseCounter(uint16_t count);
void ch32v30x_module_v11_AddInputPulseCounter(uint16_t count);
void ch32v30x_module_v11_EnableInputPulseCounter();
void ch32v30x_module_v11_DisableInputPulseCounter();
void ch32v30x_module_v11_StartUartDMA();
uint8 ch32v30x_module_v11_UartReceiveOnePackFinished(struct ch32v30x_module *self, uint16 *data_len);
void ch32v30x_module_v11_ResetSystem();
void ch32v30x_module_v11_InitPinNum(struct ch32v30x_module *self);
void ch32v30x_module_v11_UartDMASend(uint8_t *data, uint8_t len);
void ch32v30x_module_v11_SetInputPulseCouterCountUp();
void ch32v30x_module_v11_SetInputPulseCouterCountDown();
void ch32v30x_module_v11_EnableIWDG();
void ch32v30x_module_v11_EnableWWDG();
void ch32v30x_module_v11_FeedIWDG();
void ch32v30x_module_v11_FeedWWDG();
void ch32v30x_module_v11_UartSendOneByte(uint16_t data);
void ch32v30x_module_v11_DMA_Send();
void ch32v30x_module_v11_DMAAdv_Send();
void ch32v30x_module_v11_DMAHex_Send();
void ch32v30x_module_v11_JumpToBootLoader();
void ch32v30x_module_v11_HCLKSetToDiv1();
void ch32v30x_module_v11_HCLKSetToDiv2();
uint8_t ch32v30x_module_v11_ITStatusCheck_TimeUpdate();
uint8_t ch32v30x_module_v11_ITStatusCheck_EXTI();
void ch32v30x_module_v11_ITStatusClear_TimeUpdate();
void ch32v30x_module_v11_ITStatusClear_EXTI();
uint8_t ch32v30x_module_v11_GetTimDir();
#endif
